﻿using Microsoft.Reporting.WinForms;
using SD.Infrastructure.WPF.Caliburn.Aspects;
using SD.Infrastructure.WPF.Caliburn.Base;
using SlamDunk.MES.IAppService.DTOs.Outputs.PlanContext;
using SlamDunk.MES.Presentation.Maps;
using SlamDunk.MES.Presentation.Models.ReportModels;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace SlamDunk.MES.Client.ViewModels.ExecutionPlan
{
    /// <summary>
    /// 作业计划打印视图模型
    /// </summary>
    public class PrintViewModel : ScreenBase
    {
        #region # 字段及构造器

        /// <summary>
        /// 依赖注入构造器
        /// </summary>
        public PrintViewModel()
        {

        }

        #endregion

        #region # 属性

        #region 报表路径 —— string ReportPath
        /// <summary>
        /// 报表路径
        /// </summary>
        [DependencyProperty]
        public string ReportPath { get; set; }
        #endregion

        #region 报表数据源列表 —— ObservableCollection<ReportDataSource> ReportDataSources
        /// <summary>
        /// 报表数据源列表
        /// </summary>
        [DependencyProperty]
        public ObservableCollection<ReportDataSource> ReportDataSources { get; set; }
        #endregion

        #endregion

        #region # 方法

        //Initializations

        #region 加载 —— void Load(IEnumerable<ExecutionPlanInfo> executionPlans)
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="executionPlans">作业计划列表</param>
        public void Load(IEnumerable<ExecutionPlanInfo> executionPlans)
        {
            this.ReportPath = "./Content/Reports/ExecutionPlanReport.rdlc";

            IEnumerable<ExecutionPlanRp> executionPlanRps = executionPlans.Select(x => x.ToReportView());

            //设定报表数据源
            ReportDataSource saleOrderDataSource = new ReportDataSource
            {
                Name = "ExecutionPlans",
                Value = executionPlanRps
            };
            this.ReportDataSources = new ObservableCollection<ReportDataSource>
            {
                saleOrderDataSource,
            };
        }
        #endregion

        #endregion
    }
}
